package com.example.administrator.yuejian2.model;

import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.AddTrainOrderBean;
import com.example.administrator.yuejian2.service.AddTrainOrderService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.administrator.yuejian2.other.Url.BASEURL;
import static com.example.administrator.yuejian2.other.Url.URL;
import static com.example.administrator.yuejian2.other.Url.URL1;

public class AddTrainOrderModel {
    private Retrofit retrofit;
    private AddTrainOrderService addTrainOrderService;


    public AddTrainOrderModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL+URL1)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        addTrainOrderService=retrofit.create(AddTrainOrderService.class);
    }

    public void getAddTrainOrder(String train_id, String user_id, String trainorder_realname, String trainorder_tel, String trainorder_num, String trainorder_amount, String trainorder_mode, final RetrofitListener listener)
    {
        Call<AddTrainOrderBean> call=addTrainOrderService.getAddTrainOrder(train_id,user_id,trainorder_realname,trainorder_tel,trainorder_num,trainorder_amount,trainorder_mode);
        call.enqueue(new Callback<AddTrainOrderBean>() {
            @Override
            public void onResponse(Call<AddTrainOrderBean> call, Response<AddTrainOrderBean> response) {

                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<AddTrainOrderBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
}
